-
Notifications
You must be signed in to change notification settings - Fork 2
Use statements must be used #14
Conversation
tests/cases/whitespace/use-namespace
Outdated
|
|
||
| namespace Vendor; | ||
|
|
||
| new Foo(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is wrong, as the use statement is being removed. One of the new sniffs must be misbehaving. Edit: It's UseFromSameNamespace.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at it, UseFromSameNamespace is actually correct because the use statement is in the global namespace, where it's not needed. Would still rather UseBeforeNamespace is triggered.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can use a namespaced class to get round this for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Just checked what happens and the code's going to be broken either way.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thats a really useful auto-fixer 👍
| @@ -0,0 +1,25 @@ | |||
| ---DESCRIPTION--- | |||
| Use statements must not be from the same namespace | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good practice
| @@ -0,0 +1,32 @@ | |||
| ---DESCRIPTION--- | |||
| Use statements must be used | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for classes, this is expected
|
|
||
| namespace Vendor; | ||
|
|
||
| use function date; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can see this becoming annoying for many PHP functions e.g. all strlen and similar which gets used everywhere. Even Java auto-import java.lang to avoid too many imports. PHP provides the fallback too for functions (but not for classes IIRC).
If anything I would forbid defining a strlen that is not \strlen, which tries to avoid the ambiguity.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some functions get a very-minor performance boost by not checking the fallback. But more importantly prevents https://www.giorgiosironi.com/2010/09/monkey-patching-in-php.html (as used by Symfony's ClockMock).
Might be annoying when not using an IDE though...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's try it out, we can always reverse it if needed.
(It's in use at https://github.com/doctrine/doctrine2/blob/b40c2c6b7893c929f754150d480c20f9b22e0afe/lib/Doctrine/ORM/Mapping/Factory/Strategy/FileWriterClassMetadataGeneratorStrategy.php#L9-L17 if you want to try your editor.)
Requires
usestatements (so no FCQN and no global fallbacks).